<?php

declare(strict_types=1);
/**
 * Fastapp.
 * 3/7/24
 * @Author deepsea
 * @Contact telegram:deepsea159
 */

namespace App\Fastapp\Api\Controller\Account;


use App\Fastapp\Api\Controller\ApiController;
use App\Fastapp\Aspect\ApiAuth;
use App\System\Request\UploadRequest;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\PostMapping;
use Psr\Http\Message\ResponseInterface;

#[Controller(prefix: "api/upload"), ApiAuth]
class UploadController extends ApiController
{
    #[PostMapping('file')]
    public function file(UploadRequest $request): ResponseInterface
    {
        if ($request->file('file')) {
            return $this->success(upload_file($request->file('file')));
        }
        return $this->error(fastapp_t('system.upload_file_verification_fail'));
    }

    #[PostMapping('image')]
    public function image(UploadRequest $request): ResponseInterface
    {
        if ($request->file('image')) {
            return $this->success(upload_file($request->file('image')));
        }
        return $this->error(fastapp_t('system.upload_image_verification_fail'));
    }
}